const GlobalDirective = Vue => {
    /**
     * 校验行为权限,适用table,自动追加分割线
     */
    Vue.directive("auth-table-action", {
        inserted: function(el, binding, vnode) {
            let actions = vnode.context.$route.meta.actions;
            if (el.childNodes) {
                el.childNodes.forEach((element, index) => {
                    if (actions == null || !actions.includes(binding.value[index])) {
                        el.removeChild(element);
                    } else {
                        if (index > 0) {
                            let div = document.createElement("div");
                            div.role = "separator";
                            div.className = "ant-divider ant-divider-vertical";
                            el.insertBefore(div, element);
                        }
                    }
                });
            }
        },
    });
    /**
     * 校验行为权限
     */
    Vue.directive("auth-action", {
        inserted: function(el, binding, vnode) {
            let actions = vnode.context.$route.meta.actions;
            if (actions == null || !actions.includes(binding.value)) {
                el.parentNode.removeChild(el);
            }
        },
    });
};

export default GlobalDirective;
